using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Utility;
using Entities;

public partial class Admin_Danhsachdiadiem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();

        }
    }
    private void LoadData()
    {
        Pager.PageSize = 5;
        int total = 0;
        Criteria c = new Criteria();
        if (txt_tendd.Text != "")
        {
            c.add(Condition.AND, tbDiadiemCollumn .tendiadiem , Condition.LIKE, txt_tendd.Text);
        }
        tbDiadiemCollection  ddiemCollection = tbDiadiemBUS .Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
             tbDiadiemCollumn.madiadiem .ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = ddiemCollection;
        Repeater1.DataBind();

        Pager.ItemCount = total;
    }

    protected void lbt_Xoa_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_Xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbDiadiem  ddiem = tbDiadiemBUS .GetByID(id);

                tbDiadiemBUS .Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);

    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item
           || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            tbDiadiem  ddiem = (tbDiadiem)e.Item.DataItem;

            tbMien  mien= tbMienBUS .GetByID(ddiem.Mamien );
            if (mien!= null)
            {
                Label lit_m= (Label)e.Item.FindControl("lit_m");
                lit_m.Text = mien.Tenmien;
            }

            Literal lt_tdd = (Literal)e.Item.FindControl("ten_dd");


            lt_tdd.Text = ddiem .Tendiadiem ;

            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "~/Admin/Suadiadiem.aspx?id=" +ddiem .Madiadiem .ToString();
        }
    }
   
    protected void btn_timkiem_Click(object sender, EventArgs e)
    {
        LoadData();
    }
}
